home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 5 / The 640 Meg Shareware Studio CD-ROM Volume V (Data Express)(1994).ISO / amiga / tempdemo.lha / ProgrammersInfo / SKEL-ULC.c < prev    next >
C/C++ Source or Header  |  1994-05-22  |  16KB  |  555 lines

  1. //================================================================================
  2. // PROGRAM: ULC (Updater / Last Callers)
  3. // VERSION: v1.2
  4. //COMPILER: Lattice C v5.10b
  5. //    DATE: Oct 25, 1992
  6. //================================================================================
  7.  
  8. //**********************
  9. //*****  Includes  *****
  10. //**********************
  11.  
  12. #include <proto/all.h>
  13. #include <stdio.h>
  14. #include <time.h>
  15.  
  16. #include <string.h>
  17. #include <skeleton/commas.h>
  18. #include <tempest/headers.h>
  19. #include <tempest/Skel-Current.h>
  20. #include <tempest/Skel-Data.h>
  21.  
  22. void OutPut(int,int);
  23. void CurrentDay(int,int);
  24. void NewDay(void);
  25.  
  26.  
  27.  
  28. //*********************
  29. //*****  Structs  *****
  30. //*********************
  31.  
  32. struct LastCallers
  33. {
  34.  char   Name[32],Location[32];
  35.  BYTE   NodeLastOn;
  36.  USHORT UL,DL,CallsToday,NewUser,Send,Slot_Number;
  37.  long   DB,UB,TDB,TUB,Time_Last_On,Time_Last;
  38. };
  39.  
  40. char *mon[]={ "Jan","Feb","Mar","Apr","May","Jun",
  41.               "Jul","Aug","Sep","Oct","Nov","Dec" };
  42.  
  43. struct Current Current;
  44. struct SKEL SKEL;
  45.  
  46. struct User    User;
  47. struct Today   Today;
  48. struct LastCallers Last[15];
  49.  
  50. //*********************
  51. //*****  Globals  *****
  52. //*********************
  53.  
  54. char DateString[15],OUTPATH[255],shit1[255],Outname[255];
  55. int  Day,Test=0,TodayUFiles,TodayDFiles,TodayNewUsers,stat,
  56.      TotalUsers,TodayCalls,TodayMessages,TodayBusy,TodayNewUsers;
  57. long TotalCalls,TotalMessages,TotalDL,TotalUL,TodayULKB,TodayDLKB,
  58.      TotalULKB,TotalDLKB;
  59.  
  60. //******************
  61. //*****  Main  *****
  62. //******************
  63.  
  64. void main(int argc,char *argv[])
  65. {
  66.  register int i=1,j=2,m=2,x=0,y,RANK=12,NODES;
  67.  int HOLDER,Day,Month,Year,stat,fd,UserDay;
  68.  char namen[80],string[255],string1[50],RMonth[50];
  69.  
  70.  struct tm *zt;
  71.  time_t just;
  72.  time(&just);
  73.  zt   = localtime(&just);
  74.  Day  = zt->tm_mday;
  75.  Month= zt->tm_mon + 1;
  76.  Year = zt->tm_year;
  77.  strcpy(RMonth,mon[Month-1]);
  78.  sprintf(DateString,"%2d%2d%d",Day,Month,Year);
  79.  NODES = argc - 2;
  80.  
  81. //***********************
  82. //*****  Interface  *****
  83. //***********************
  84.  
  85.  sprintf(shit1,"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"");
  86.  if(argc!=4)
  87.   {
  88.    puts("\n    _______ _________");
  89.    puts("   / ___/ // / ___/ /    [SKEL-ULC v2.0] - Updater/Last Callers");
  90.    puts("  /__  /   _/ ___/ /__");
  91.    puts(" /____/_/\\_)____/____/   For Tempest BBS - [Programmer: Michael Bockert]");
  92.    puts(shit1);
  93.    puts("   USAGE: SKEL-ULC [#Nodes] [OutFile] [SetupDir Path]");
  94.    puts(" EXAMPLE: SKEL-ULC 5 RAM:Test TEMPEST:");
  95.    puts(" [#Nodes] Number of Nodes\n");
  96.    puts("[OutFile] Path of Last Callers Output File\n");
  97.    puts("  [Setup] Path to Setup Directory");
  98.    exit(0);
  99.   }
  100.  NODES=atoi(argv[1]);
  101.  strcpy(OUTPATH,argv[2]);
  102.  
  103. //************************************
  104. //*****  Load Skel-Current.Data  *****
  105. //************************************
  106.  
  107.   fd=Open("S:SKEL-Current.Data",MODE_OLDFILE);
  108.   if(fd==0)
  109.      Test = 1;
  110.   else
  111.    {
  112.     stat=Read(fd,(char *)&Current, sizeof(struct Current));
  113.     if(stat!=sizeof(struct Current))
  114.      {
  115.       Close(fd);
  116.       puts("\nWrong Current.Data in S:, Delete It\n");
  117.       exit(0);
  118.      }
  119.    }
  120.   Close(fd);
  121.  
  122. //*************************************
  123. //*****  Load Runtime.Data Files  *****
  124. //*************************************
  125.  
  126.  do
  127.   {
  128.    sprintf(namen,"%sSetup/Runtime-%d.data",argv[3],i);
  129.    fd=Open(namen,MODE_OLDFILE);
  130.    if(fd==0)
  131.     {
  132.      puts("\nA Runtime.Data file was not found!\n");
  133.      exit(0);
  134.     }
  135.    Read(fd,(char *)&Today, sizeof(struct Today));
  136.    Close(fd);
  137.    TodayBusy     += Today.Busy;
  138.    TodayNewUsers += Today.New;
  139.    TotalCalls    += Today.Total;
  140.    i++;
  141.   }
  142.  while(i<NODES+1);
  143.  
  144. //**************************************
  145. //*****  Load Skel-Data.Data  **********
  146. //**************************************
  147.  
  148.  sprintf(Outname,"%sSetup/Skel-Data.Data",argv[3]);
  149.  fd=Open(Outname,MODE_OLDFILE);
  150.  if(fd!=0)
  151.   {
  152.    Read(fd,(char *)&SKEL, sizeof(struct SKEL));
  153.    Close(fd);
  154.   }
  155.  
  156. //********************************
  157. //*****  Load Accounts.Data  *****
  158. //********************************
  159.  
  160.  sprintf(string,"%sAccounts.data",argv[3]);
  161.  fd=Open(string,MODE_OLDFILE);
  162.  Read(fd,(char *)&User, sizeof(struct User));
  163.  do
  164.   {
  165.    if(User.Slot_Number != 0)
  166.     {
  167.      if(Test == 1)
  168.       {
  169.        TotalMessages += User.Total_Posts;
  170.        TotalUL   += User.Total_ULFiles;
  171.        TotalDL   += User.Total_DLFiles;
  172.        TotalULKB += ((User.Total_ULBytes + 1L) / 1024L);
  173.        TotalDLKB += ((User.Total_DLBytes + 1L) / 1024L);
  174.       }
  175.      TotalUsers ++;
  176.      strcpy(string,ctime(&User.Time_Last_Connect));
  177.      strmid(string,string1,9,2);
  178.      UserDay   = atoi(string1);
  179.      strmid(string,string1,5,3);
  180.      if( (strcmp(string1,RMonth)==0) && (UserDay == Day) )
  181.       {
  182.        TodayCalls    += User.Period_Calls;
  183.        TodayMessages += User.Period_Posts;
  184.        TodayUFiles   += User.Period_ULFiles;
  185.        TodayULKB     += ((User.Period_ULBytes + 1L) / 1024L);
  186.        TodayDFiles   += User.Period_DLFiles;
  187.        TodayDLKB     += ((User.Period_DLBytes + 1L) / 1024L);
  188.       }
  189.      if(User.Slot_Number < 2)
  190.         goto DONE;
  191.     }
  192.    x=0;
  193.    do
  194.     {
  195.      if(User.Time_Last_Connect >= Last[x].Time_Last)
  196.       {
  197.        HOLDER = x;
  198.        y=0;
  199.        do
  200.         {
  201.          y++;
  202.          CopyMem((char *)&Last[RANK-(y+1)],(char *)&Last[RANK-y],sizeof(struct LastCallers));
  203.          x++;
  204.         }
  205.        while(x+1<RANK);
  206.        x=HOLDER;
  207.        strcpy(Last[x].Name,User.Name);
  208.        strcpy(Last[x].Location,User.City);
  209.        Last[x].UL           = User.Period_ULFiles;
  210.        Last[x].DL           = User.Period_DLFiles;
  211.        Last[x].TDB          = User.Total_DLBytes;
  212.        Last[x].TUB          = User.Total_ULBytes;
  213.        Last[x].CallsToday   = User.Period_Calls;
  214.        if(User.Status==2) Last[x].NewUser=1;
  215.        else               Last[x].NewUser=0;
  216.        Last[x].Send         = User.Period_Posts;
  217.        Last[x].Time_Last_On = User.Time_Last_Logoff;
  218.        Last[x].Time_Last    = User.Time_Last_Connect;
  219.        Last[x].NodeLastOn   = User.NodeLastOn;
  220.        Last[x].Slot_Number  = User.Status;
  221.        goto DONE;
  222.       }
  223.      x++;
  224.     }
  225.    while(x<RANK);
  226.  
  227.    DONE:
  228.    stat=Read(fd,(char *)&User, sizeof(struct User));
  229.   }
  230.  while(stat > 0);
  231.  Close(fd);
  232.  OutPut(NODES,RANK);
  233.  
  234. //**************************
  235. //*****  Updater Part  *****
  236. //**************************
  237.  
  238.  if(Test == 1)
  239.   {
  240.    CurrentDay(NODES,Day);
  241.    NewDay();
  242.    puts("\nRemember! Some stats are creaetd after midnight tonight!\n");
  243.   }
  244.  else
  245.   {
  246.    if(Day == Current.Day)
  247.     {
  248.      CurrentDay(NODES,Day);
  249.     }
  250.    else
  251.     {
  252.      NewDay();
  253.      CurrentDay(NODES,Day);
  254.     }
  255.   }
  256.  puts("\nSKEL-ULC Done!\n");
  257.  exit(0);
  258. }
  259.  
  260. //********************
  261. //*****  Output  *****
  262. //********************
  263.  
  264. void OutPut(int NODES,int RANK)
  265. {
  266.  register int x=0,Connected;
  267.  char  time[180],Connected1[40],Ratio2[40],ampm[15],node[25],
  268.        Activity2[80],string[255];
  269.  float Ratio;
  270.  FILE *out2;
  271.  out2=fopen(OUTPATH,"w");
  272.  if(out2==NULL)
  273.   {
  274.    puts("Error writing output file!\n");
  275.    exit(0);
  276.   }
  277.  
  278.  fprintf(out2,"\f~+[SKEL-ULC v2.0Last Callers for %dNode(s)     By Michael Bockert [12-28-93]\n",
  279.                        NODES);
  280.  fprintf(out2,"%s\"\"\"\"\"\"\"\n",shit1);
  281.  fprintf(out2," Connect Min Ratio CT  Acts Node Alias/Handle         Location/Group\n");
  282.  fprintf(out2,"========-===-=====-==-=====-====-====================-=========================\n");
  283.  do
  284.   {
  285.    strcpy(string,ctime(&Last[x].Time_Last));
  286.    strmid(string,time,12,5);
  287. //***************************
  288. //*****  Convert AM/PM  *****
  289. //***************************
  290.    strcpy(ampm," pm");
  291.    if((time[0] == '1') && (time[1] != '0') && (time[1] != '1'))
  292.     {
  293.      time[0] = ' ';
  294.      if(time[1] == '2') time[0] = '1';
  295.      else if(time[1] == '3') time[1] = '1';
  296.        else if(time[1] == '4') time[1] = '2';
  297.          else if(time[1] == '5') time[1] = '3';
  298.            else if(time[1] == '6') time[1] = '4';
  299.              else if(time[1] == '7') time[1] = '5';
  300.                else if(time[1] == '8') time[1] = '6';
  301.                  else if(time[1] == '9') time[1] = '7';
  302.     }
  303.    else
  304.     {
  305.      if(time[0] == '2')
  306.       {
  307.        if(time[1] == '0') { time[0] = ' '; time[1] = '8'; }
  308.        else if(time[1] == '1') { time[0] = ' '; time[1] = '9'; }
  309.          else if(time[1] == '2') { time[0] = '1'; time[1] = '0'; }
  310.            else if(time[1] == '3') { time[0] = '1'; time[1] = '1'; }
  311.       }
  312.      else
  313.       {
  314.        ampm[1]='a';
  315.        if((time[0] == '0') && (time[1] == '0')) { time[0] = '1'; time[1] = '2'; }
  316.        else
  317.          if(time[0] != '1') time[0] = ' ';
  318.       }
  319.     }
  320.    Connected = ((Last[x].Time_Last_On - Last[x].Time_Last)/60)+1;
  321.    sprintf(Connected1,"%d",Connected);
  322. //*****************************
  323. //*****  Figure Activity  *****
  324. //*****************************
  325.    if(Last[x].NewUser > 0)
  326.     {
  327.      strcpy(Activity2,"=New=");
  328.      strcpy(Ratio2," -.--");
  329.      goto PRINT;
  330.     }
  331.    else
  332.     {
  333.      if(Last[x].Slot_Number== 0)
  334.       {
  335.        strcpy(Activity2,"=DEL=");
  336.        strcpy(Ratio2," -.--");
  337.        goto PRINT;
  338.       }
  339.      else
  340.       {
  341.        strcpy(Activity2,"-----");
  342.        if(Last[x].UL > 0)   Activity2[0]  = 'U';
  343.        if(Last[x].DL > 0)   Activity2[12] = 'D';
  344.        if(Last[x].Send > 0) Activity2[24] = 'P';
  345.       }
  346.     }
  347.    if(Connected < 0)
  348.       strcpy(Connected1,"n/a");
  349. //**************************
  350. //*****  Figure Ratio  *****
  351. //**************************
  352.    Ratio = (float) (Last[x].TDB+1) / (Last[x].TUB+1);
  353.    if((Ratio>10.00) || (Last[x].TDB < 1000000L) && (Last[x].TUB < 1000000L))
  354.       strcpy(Ratio2," -.--");
  355.    else
  356.     {
  357.      if(Ratio>3.00)
  358.         strcpy(Ratio2,"LEECH");
  359.      else
  360.       {
  361.        if( (Ratio < 0.16) && (Ratio >= 0.00) && (Last[x].TUB >= 5000000L) )
  362.            strcpy(Ratio2,"ELITE");
  363.        else
  364.            sprintf(Ratio2,"%4.2f",Ratio);
  365.       }
  366.     }
  367.    if(Last[x].NodeLastOn<0) Last[x].NodeLastOn=0;
  368.    if(Last[x].NodeLastOn>99) Last[x].NodeLastOn=0;
  369.    if(Last[x].NodeLastOn<10) sprintf(node,"0%d",Last[x].NodeLastOn);
  370.    else                      sprintf(node,"%d" ,Last[x].NodeLastOn);
  371.  
  372.    PRINT:
  373.  
  374.    fprintf(out2,"%s%s %3s %5s %2d %s  %2s  %-20.20s %-25.25s\n",
  375.       time,ampm,Connected1,Ratio2,Last[x].CallsToday,Activity2,node,Last[x].Name,Last[x].Location);
  376.    x++;
  377.   }
  378.  while(x<RANK);
  379.  fprintf(out2,"\n[TODAY]   Mins Busy [%4d]   Total Calls [%7.7s]   [Y-DAY]   Mins Busy [%4d]\n",
  380.                                      TodayBusy,commas(SKEL.TotalCalls,buff),SKEL.HBusy[1]);
  381.  fprintf(out2,"Calls [%3dMessages [%3d]    Total Msgs [%7s]   Calls [%3dMessages [%3d]\n",
  382.                TodayCalls,TodayMessages,commas(SKEL.TotalMessages,buff),SKEL.HCalls[1],SKEL.HMessages[1]);
  383.  fprintf(out2,"UL's  [%3d] / [%7skb   Total Users     [%3d]   UL's  [%3d] / [",
  384.                       TodayUFiles,commas(TodayULKB,buff),TotalUsers,SKEL.HUL[1]);
  385.  fprintf(out2,"%7.7skb\n",commas(SKEL.HULKB[1],buff));
  386.  fprintf(out2,"DL's  [%3d] / [%7skb     New Users      [%2d]   DL's  [%3d] / [",
  387.                TodayDFiles,commas(TodayDLKB,buff),TodayNewUsers,SKEL.HDL[1]);
  388.  fprintf(out2,"%7skb\n",commas(SKEL.HDLKB[1],buff));
  389.  fprintf(out2,"%s\"\"\"\"\"\"\"~r\n",shit1);
  390.  fclose(out2);
  391. }
  392.  
  393. //**************************
  394. //**************************
  395. //*****  Current Day!  *****
  396. //**************************
  397. //**************************
  398.  
  399. void CurrentDay(int NODES,int Day)
  400. {
  401.  register int fd;
  402.  
  403.  Current.Calls      = TodayCalls;
  404.  Current.Messages   = TodayMessages;
  405.  Current.Busy       = TodayBusy;
  406.  Current.NewUsers   = TodayNewUsers;
  407.  Current.UL         = TodayUFiles;
  408.  Current.ULKB       = TodayULKB;
  409.  Current.DL         = TodayDFiles;
  410.  Current.DLKB       = TodayDLKB;
  411.  Current.Users      = TotalUsers;
  412.  Current.Nodes      = NODES;
  413.  Current.Day        = Day;
  414.  strcpy(Current.Date,DateString);
  415.  
  416. //*************************************
  417. //*****  Write Skel-Current.Data  *****
  418. //*************************************
  419.  
  420.  fd=Open("S:Skel-Current.Data",MODE_NEWFILE);
  421.  if(fd==0)
  422.   {
  423.    puts("Error writing S:Skel-Current.Data\n");
  424.    exit(0);
  425.   }
  426.  Write(fd,(char *)&Current, sizeof(struct Current));
  427.  Close(fd);
  428. }
  429.  
  430. //**********************
  431. //**********************
  432. //*****  New Day!  *****
  433. //**********************
  434. //**********************
  435.  
  436. void NewDay()
  437. {
  438.  register int i,j,fd;
  439.  
  440.  if(Test != 1)
  441.   {
  442. //******************************
  443. //*****  Get History Data  *****
  444. //******************************
  445.    i = 29;
  446.    j = 30;
  447.    do
  448.     {
  449.      SKEL.HCalls[j]     = SKEL.HCalls[i];
  450.      SKEL.HMessages[j]  = SKEL.HMessages[i];
  451.      SKEL.HBusy[j]      = SKEL.HBusy[i];
  452.      SKEL.HNewUsers[j]  = SKEL.HNewUsers[i];
  453.      SKEL.HUL[j]        = SKEL.HUL[i];
  454.      SKEL.HULKB[j]      = SKEL.HULKB[i];
  455.      SKEL.HDL[j]        = SKEL.HDL[i];
  456.      SKEL.HDLKB[j]      = SKEL.HDLKB[i];
  457.      strcpy(SKEL.HDate[j],SKEL.HDate[i]);
  458.      i--;
  459.      j--;
  460.     }
  461.    while(i > 0);
  462.  
  463. //**********************************
  464. //*****  Get Yesterday's Data  *****
  465. //**********************************
  466.  
  467.    SKEL.HCalls[1]     = Current.Calls;
  468.    SKEL.HMessages[1]  = Current.Messages;
  469.    SKEL.HBusy[1]      = Current.Busy;
  470.    SKEL.HNewUsers[1]  = Current.NewUsers;
  471.    SKEL.HUL[1]        = Current.UL;
  472.    SKEL.HULKB[1]      = Current.ULKB;
  473.    SKEL.HDL[1]        = Current.DL;
  474.    SKEL.HDLKB[1]      = Current.DLKB;
  475.    strcpy(SKEL.HDate[1],Current.Date);
  476.  
  477. //*****************************
  478. //*****  Get New Records  *****
  479. //*****************************
  480.  
  481.    if(SKEL.HCalls[1] > SKEL.RCalls)
  482.     {
  483.      SKEL.RCalls = SKEL.HCalls[1];
  484.      strcpy(SKEL.RDates[1],SKEL.HDate[1]);
  485.     }
  486.    if(SKEL.HMessages[1] > SKEL.RMessages)
  487.     {
  488.      SKEL.RMessages = SKEL.HMessages[1];
  489.      strcpy(SKEL.RDates[2],SKEL.HDate[1]);
  490.     }
  491.    if(SKEL.HBusy[1] > SKEL.RBusy)
  492.     {
  493.      SKEL.RBusy = SKEL.HBusy[1];
  494.      strcpy(SKEL.RDates[3],SKEL.HDate[1]);
  495.     }
  496.    if(SKEL.HNewUsers[1] > SKEL.RNewUsers)
  497.     {
  498.      SKEL.RNewUsers = SKEL.HNewUsers[1];
  499.      strcpy(SKEL.RDates[4],SKEL.HDate[1]);
  500.     }
  501.    if(SKEL.HUL[1] > SKEL.RUL)
  502.     {
  503.      SKEL.RUL = SKEL.HUL[1];
  504.      strcpy(SKEL.RDates[5],SKEL.HDate[1]);
  505.     }
  506.    if(SKEL.HULKB[1] > SKEL.RULKB)
  507.     {
  508.      SKEL.RULKB = SKEL.HULKB[1];
  509.      strcpy(SKEL.RDates[6],SKEL.HDate[1]);
  510.     }
  511.    if(SKEL.HDL[1] > SKEL.RDL)
  512.     {
  513.      SKEL.RDL = SKEL.HDL[1];
  514.      strcpy(SKEL.RDates[7],SKEL.HDate[1]);
  515.     }
  516.    if(SKEL.HDLKB[1] > SKEL.RDLKB)
  517.     {
  518.      SKEL.RDLKB = SKEL.HDLKB[1];
  519.      strcpy(SKEL.RDates[8],SKEL.HDate[1]);
  520.     }
  521. //*****************************
  522. //*****  Get Totals Data  *****
  523. //*****************************
  524.    SKEL.TotalCalls    += Current.Calls;
  525.    SKEL.TotalMessages += Current.Messages;
  526.    SKEL.TotalUL       += Current.UL;
  527.    SKEL.TotalDL       += Current.DL;
  528.    SKEL.TotalULKB     += Current.ULKB;
  529.    SKEL.TotalDLKB     += Current.DLKB;
  530.   }
  531.  else
  532.   {
  533.    SKEL.TotalCalls     = TotalCalls;
  534.    SKEL.TotalMessages  = TotalMessages;
  535.    SKEL.TotalUL        = TotalUL;
  536.    SKEL.TotalDL        = TotalDL;
  537.    SKEL.TotalULKB      = TotalULKB;
  538.    SKEL.TotalDLKB      = TotalDLKB;
  539.   }
  540.  SKEL.TotalUsers       = TotalUsers;
  541.  
  542. //**********************************
  543. //*****  Write Skel-Data.Data  *****
  544. //**********************************
  545.  
  546.  fd=Open(Outname,MODE_NEWFILE);
  547.  if(fd==0)
  548.   {
  549.    puts("Error writing Skel-Data.Data!\n");
  550.    exit(0);
  551.   }
  552.  Write(fd,(char *)&SKEL, sizeof(struct SKEL));
  553.  Close(fd);
  554. }
  555.